package com.fjh.module.rbac.service.impl;

import java.io.IOException;

import com.fjh.common.constant.Constants;
import com.fjh.common.manager.AsyncManager;
import com.fjh.common.manager.factory.AsyncFactory;
import com.fjh.security.easy.starter.authentication.service.EasyAuthSuccessService;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * @author fanjh37
 */
@Service
public class EasyAuthSuccessServiceImpl implements EasyAuthSuccessService {

    @Override
    public void handle(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse, Authentication authentication)
        throws IOException, ServletException {
        // 记录用户登录成功日志
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        AsyncManager.me().execute(
            AsyncFactory.recordLogininfor(userDetails.getUsername(), Constants.LOGIN_SUCCESS,
                "登录成功"));
    }
}
